<?

require_once("mysql.php");

$q = "SELECT 
               deal.id, 
               user.name, 
               deal.item, 
               deal.photo as item_image, 
               deal.value, 
               deal.location as online,
               seller.name as seller, 
               seller.photo as seller_image,
               seller.reference, 
               deal.time, 
               location.location, 
               location.latitude, 
               location.longitude 

      FROM deal 

      LEFT JOIN seller   ON deal.seller     = seller.id 
      LEFT JOIN location ON seller.location = location.id OR deal.location = location.id
      LEFT JOIN user     ON deal.user       = user.id 

      WHERE deal.flags = 1

      ORDER BY time DESC";

 
$r = MYSQL_Q($q);

$result = array();

while ($row = mysql_fetch_assoc($r)) {
 

    array_push($result, $row);

    if (count($result) > 40) break;
}

echo json_encode($result, true);

?>
